package com.online.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.online.entity.Message;
import org.apache.ibatis.annotations.*;

@Mapper
public interface MessageMapper {
    /**
     * 查看所有留言
     * @param messagePage
     * @return
     */
    @Results({
            @Result(property = "replays", column = "temp_id",many = @Many(select = "com.exam.mapper.ReplayMapper.findAllById"))
    })
    IPage<Message> findAll(Page<Message> messagePage);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Results({
            @Result(property = "replays", column = "id",many = @Many(select = "com.exam.mapper.ReplayMapper.findAllById"))
    })
    Message findById(Integer id);

    /**
     * 删除留言
     * @param id
     * @return
     */
    int delete(Integer id);

    /**
     * 新增留言
     * @param message
     * @return
     */
    @Options(useGeneratedKeys = true,keyProperty = "id")
    int add(Message message);

    @Update("update message set title = #{title}, content = #{content}, time = #{time} where " +
            "id = #{id}")
    int update(Message message);
}
